'use strict';

import { Body, Controller, Inject, Post, Provide} from '@midwayjs/decorator';
import RoleUserService from "../service/roleUserService";

@Provide()
@Controller('/roleUser')
export class RoleUserController {
  @Inject()
  roleUserService: RoleUserService;

  @Post('/save')
  async roleUserSave(@Body('roleUserList') data: object) {
    const rs = await this.roleUserService.save(data).catch(err => {
      return {
        success: false,
        msg:'保存失败'
      }
    })
    return rs
  }
  @Post('/delete')
  async roleUserDelete(@Body('roleUserList') data: object) {
    const rs = await this.roleUserService.delete(data).catch(err => {
      return {
        success: false,
        msg:'删除失败'
      }
    })
    return rs
  }
  @Post('/getRoleUserList')
  async getRoleUserList(@Body('roleId') roleId: string) {
    //获取已分配角色用户
    const rs = await this.roleUserService.getRoleUserList(roleId).catch(err=>{
        return {
          success: false,
          msg:'获取数据失败'
        }
    })
    return rs;
  }
  @Post('/getNotRoleUserList')
  async getNotRoleUserList(@Body('roleId') roleId: string) {
    //获取未分配角色用户
    const rs = await this.roleUserService.getNotRoleUserList(roleId).catch(err => {
      return {
        success: false,
        msg:'获取数据失败'
      }
    })
    return rs
  }
}
